﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAL;
using System.Data;

namespace BLL.Util
{
    public class Config
    {
        /// <summary>
        /// 从数据库获取利率列表
        /// </summary>
        /// <returns></returns>
        internal static List<ConstRate> GetRateByDB()
        {
            ConfigDAL dal = new ConfigDAL();
            List<ConstRate> list = new List<ConstRate>();
            foreach (DataRow row in dal.GetRate().Rows)
            {
                ConstRate rate = new ConstRate()
                {
                    ID = int.Parse(row["ID"].ToString()),
                    Months = int.Parse(row["Months"].ToString()),
                    Rate = float.Parse(row["Rate"].ToString()),
                    Title = row["Title"].ToString()
                };
                list.Add(rate);
            }
            return list;
        }
        /// <summary>
        /// 获取利率实例
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ConstRate GetRateByID(int id)
        {
            return CacheHelper.GetRate().Where(p => p.ID == id).SingleOrDefault();
        }
    }
}
